package com.hxl.demo.service.Impl;

import com.hxl.demo.entity.TrainingClassification;
import com.hxl.demo.entity.TrainingContents;
import com.hxl.demo.mapper.TrainingClassificationMapper;
import com.hxl.demo.mapper.TrainingContentsMapper;
import com.hxl.demo.service.TrainingContentsService;
import com.hxl.demo.tools.Common;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Service
public class TrainingContentsServiceImpl implements TrainingContentsService {

    @Resource
    private TrainingContentsMapper trainingContentsMapper;

    @Resource
    private  TrainingClassification trainingClassification;

    @Resource
    private TrainingClassificationMapper trainingClassificationMapper;

    public List<TrainingContents> getTrainingContents(Integer id){
        return trainingContentsMapper.getTrainingContents(id);
    }

    public TrainingContents getTrainingContentsDetail(Integer id) {
        return    trainingContentsMapper.getTrainingContentsDetail(id);
    }

    @Override
    public Object trainingContentsAdd(Integer classId, String content, String url, Integer trainingTime,String remark,Integer userId) {
        trainingClassification=  trainingClassificationMapper.getTrainingClassificationById(classId);
        if(trainingClassification==null){
            return Common.returnJsonFail("所属分类不存在",400);
        }

      Integer res=  trainingContentsMapper.trainingContentsAdd(classId,content,url,trainingTime,remark,userId,new Date());
        if(res>0){
            return Common.returnJsonFail("操作成功",200);
        }

        return Common.returnJsonFail("操作失败",400);
    }

    @Override
    public Object trainingContentAudit(Integer id, String auditStatus) {
        String status="1";

       if(auditStatus.equals("2")){
           status="0";
       }

        Integer res=trainingContentsMapper.trainingContentAudit(id,auditStatus,status);

       if(res>0){
           return Common.returnJsonFail("操作成功",200);
       }
        return Common.returnJsonFail("操作失败",400);
    }


}
